package com.moli.iov.protocol.model.realtime;

import com.moli.iov.protocol.codec.Serialize;
import com.moli.iov.protocol.enums.CommonEnableTag;
import com.moli.iov.protocol.enums.CommonLockTag;
import com.moli.iov.protocol.enums.CommonOpenTag;
import com.moli.iov.protocol.enums.CommonSwitchTag;
import com.moli.iov.protocol.enums.extend.*;
import com.moli.iov.protocol.model.EntityBytesLen;
import com.moli.iov.util.ByteArrayUtil;

import java.io.Serializable;


@Serialize(unit = "byte", isBigEndian = true)
public class ExtendVehicleState implements Serializable, EntityBytesLen {


    @Serialize(unit = "byte", offset = 0, size = 2)
    public int extendLength;


    public int getExtendLength() {
        return extendLength;
    }

    public void setExtendLength(int extendLength) {
        this.extendLength = extendLength;
    }

    @Override
    public int getBytesLen() {
        return extendLength + 3;
    }

    /**
     *
     */
    private static final long serialVersionUID = 8116185218320180434L;

    /**
     * 电源档位
     */
    @Serialize(unit = "byte", offset = 2, size = 1)
    public ExtendPowerGearTag extendPowerGear;

    /**
     * 租赁模式
     */
    public byte extendLeasingModel;

    /**
     * 车门状态
     */
    public byte extendDoorState;

    /**
     * 车窗状态
     */
    public byte extendWindowState;

    /**
     * 中控锁状态
     */
    @Serialize(unit = "byte", offset = 6, size = 1)
    public ExtendControlLockStateTag extendControlLockState;

    /**
     * 灯光状态
     */
    public byte extendLightState;

    /**
     * 手刹状态
     */
    @Serialize(unit = "byte", offset = 8, size = 1)
    public ExtendHandBrakeStateTag extendHandBrakeState;

    /**
     * 蓄电池电压
     */
    private double extendBatteryVoltage;

    /**
     * 充电枪状态
     */
    @Serialize(unit = "byte", offset = 10, size = 1)
    public ExtendChargingGunStateTag extendChargingGunState;

    /**
     * 定位是否有效
     */
    @Serialize(unit = "byte", offset = 11, size = 1)
    public ExtendLocationStateTag extendLocationState;

    /**
     * GPS 里程
     */
    @Serialize(unit = "byte", offset = 12, size = 4)
    public int extendGpsOde;

    /**
     * GPS 速度
     */
    @Serialize(unit = "byte", offset = 16, size = 2)
    public int extendGpsSpeed;

    /**
     * GPS 方向角
     */
    @Serialize(unit = "byte", offset = 18, size = 2)
    public int extendGpsDirection;

    /**
     * 终端定位星数
     */
    @Serialize(unit = "byte", offset = 20, size = 1)
    public int extendDeviceLocationCount;

    /**
     * 通信信号强度
     */
    @Serialize(unit = "byte", offset = 21, size = 1)
    public int extendSignalIntensity;

    /**
     * 基于bit转换的属性
     **/
    //租赁模式
    private ExtendLeasingModelTag extendLeasing;
    //usb上网状态
    private CommonOpenTag usbInternetState;
    //蓝牙状态
    private CommonLockTag bluetoothState;
    //动力状态
    private CommonLockTag dynamicState;
    //物理钥匙
    private CommonEnableTag physicalKeyState;

    //左前门
    private CommonSwitchTag leftFrontDoor;
    //右后门
    private CommonSwitchTag rightBackDoor;
    //右前门
    private CommonSwitchTag rightFrontDoor;
    //左后门
    private CommonSwitchTag leftBackDoor;
    //后箱门
    private CommonSwitchTag rearDoor;

    //车门状态预留
    private CommonSwitchTag DoorState5;

    private CommonSwitchTag DoorState6;

    private CommonSwitchTag DoorState7;

    //左前窗
    private CommonSwitchTag leftFrontWindow;
    //右后窗
    private CommonSwitchTag rightBackWindow;
    //右前窗
    private CommonSwitchTag rightFrontWindow;
    //左后窗
    private CommonSwitchTag leftBackWindow;

    //车窗状态预留
    private CommonSwitchTag window4;

    private CommonSwitchTag window5;

    private CommonSwitchTag window6;

    private CommonSwitchTag window7;

    //近光灯
    private CommonSwitchTag lowBeam;
    //近光灯
    private CommonSwitchTag highBeam;
    //前雾灯
    private CommonSwitchTag frontFogLamp;
    //后雾灯
    private CommonSwitchTag rearFogLamp;
    //阅读灯
    private CommonSwitchTag readingLamp;
    //车灯预留
    private CommonSwitchTag lamp5;
    private CommonSwitchTag lamp6;
    private CommonSwitchTag lamp7;


    @Serialize(unit = "byte", offset = 3, size = 1)
    public byte getExtendLeasingModel() {
        return extendLeasingModel;
    }

    @Serialize(unit = "byte", offset = 3, size = 1)
    public void setExtendLeasingModel(byte extendLeasingModel) {

        int[] bits = ByteArrayUtil.byteToBitArray(extendLeasingModel);

        if (bits.length == 8) {
            //租赁模式
            setExtendLeasing(ExtendLeasingModelTag.valueOf(bits[0]));
            //usb上网状态
            setUsbInternetState(CommonOpenTag.valueOf(bits[1]));
            //蓝牙状态
            setBluetoothState(CommonLockTag.valueOf(bits[2]));
            //动力状态
            setDynamicState(CommonLockTag.valueOf(bits[3]));
            //物理钥匙
            setPhysicalKeyState(CommonEnableTag.valueOf(bits[4]));
        }
        this.extendLeasingModel = extendLeasingModel;
    }

    @Serialize(unit = "byte", offset = 4, size = 1)
    public byte getExtendDoorState() {
        return extendDoorState;
    }

    @Serialize(unit = "byte", offset = 4, size = 1)
    public void setExtendDoorState(byte extendDoorState) {

        int[] bits = ByteArrayUtil.byteToBitArray(extendDoorState);


        if (bits.length == 8) {
            //左前门
            setLeftFrontDoor(CommonSwitchTag.valueOf(bits[0]));
            //右后门
            setRightBackDoor(CommonSwitchTag.valueOf(bits[1]));
            //右前门
            setRightFrontDoor(CommonSwitchTag.valueOf(bits[2]));
            //左后门
            setLeftBackDoor(CommonSwitchTag.valueOf(bits[3]));
            //后箱门
            setRearDoor(CommonSwitchTag.valueOf(bits[4]));

            //车门状态预留
            setDoorState5(CommonSwitchTag.valueOf(bits[5]));
            setDoorState6(CommonSwitchTag.valueOf(bits[6]));
            setDoorState7(CommonSwitchTag.valueOf(bits[7]));

        }


        this.extendDoorState = extendDoorState;
    }

    @Serialize(unit = "byte", offset = 5, size = 1)
    public byte getExtendWindowState() {
        return extendWindowState;
    }

    @Serialize(unit = "byte", offset = 5, size = 1)
    public void setExtendWindowState(byte extendWindowState) {

        int[] bits = ByteArrayUtil.byteToBitArray(extendWindowState);

        if (bits.length == 8) {
            //左前窗
            setLeftFrontWindow(CommonSwitchTag.valueOf(bits[0]));
            //右后窗
            setRightBackWindow(CommonSwitchTag.valueOf(bits[1]));
            //右前窗
            setRightFrontWindow(CommonSwitchTag.valueOf(bits[2]));
            //左后窗
            setLeftBackWindow(CommonSwitchTag.valueOf(bits[3]));

            //车窗状态预留
            setWindow4(CommonSwitchTag.valueOf(bits[4]));
            setWindow5(CommonSwitchTag.valueOf(bits[5]));
            setWindow6(CommonSwitchTag.valueOf(bits[6]));
            setWindow7(CommonSwitchTag.valueOf(bits[7]));
        }
        this.extendWindowState = extendWindowState;
    }

    @Serialize(unit = "byte", offset = 7, size = 1)
    public byte getExtendLightState() {
        return extendLightState;
    }

    @Serialize(unit = "byte", offset = 7, size = 1)
    public void setExtendLightState(byte extendLightState) {
        int[] bits = ByteArrayUtil.byteToBitArray(extendLightState);

        if (bits.length == 8) {
            //近光灯
            setLowBeam(CommonSwitchTag.valueOf(bits[0]));
            //远光灯
            setHighBeam(CommonSwitchTag.valueOf(bits[1]));
            //前雾灯
            setFrontFogLamp(CommonSwitchTag.valueOf(bits[2]));
            //后雾灯
            setRearFogLamp(CommonSwitchTag.valueOf(bits[3]));
            //阅读灯
            setReadingLamp(CommonSwitchTag.valueOf(bits[4]));

            //车灯状态预留
            setLamp5(CommonSwitchTag.valueOf(bits[5]));
            setLamp6(CommonSwitchTag.valueOf(bits[6]));
            setLamp7(CommonSwitchTag.valueOf(bits[7]));
        }


        this.extendLightState = extendLightState;
    }


    public ExtendPowerGearTag getExtendPowerGear() {
        return extendPowerGear;
    }

    public void setExtendPowerGear(ExtendPowerGearTag extendPowerGear) {
        this.extendPowerGear = extendPowerGear;
    }

    public ExtendControlLockStateTag getExtendControlLockState() {
        return extendControlLockState;
    }

    public void setExtendControlLockState(
            ExtendControlLockStateTag extendControlLockState) {
        this.extendControlLockState = extendControlLockState;
    }

    public ExtendHandBrakeStateTag getExtendHandBrakeState() {
        return extendHandBrakeState;
    }

    public void setExtendHandBrakeState(ExtendHandBrakeStateTag extendHandBrakeState) {
        this.extendHandBrakeState = extendHandBrakeState;
    }

    @Serialize(unit = "byte", offset = 9, size = 1, coefficient = 0.1)
    public double getExtendBatteryVoltage() {
        return this.extendBatteryVoltage;
    }


    @Serialize(unit = "byte", offset = 9, size = 1)
    public void setExtendBatteryVoltage(int extendBatteryVoltage) {
        this.extendBatteryVoltage = Double.parseDouble(String.valueOf(extendBatteryVoltage)) / 10;
    }

    public void setBatteryVoltage(double extendBatteryVoltage) {
        this.extendBatteryVoltage = extendBatteryVoltage;
    }

    public ExtendChargingGunStateTag getExtendChargingGunState() {
        return extendChargingGunState;
    }

    public void setExtendChargingGunState(
            ExtendChargingGunStateTag extendChargingGunState) {
        this.extendChargingGunState = extendChargingGunState;
    }

    public ExtendLocationStateTag getExtendLocationState() {
        return extendLocationState;
    }

    public void setExtendLocationState(ExtendLocationStateTag extendLocationState) {
        this.extendLocationState = extendLocationState;
    }

    public int getExtendGpsOde() {
        return extendGpsOde;
    }

    public void setExtendGpsOde(int extendGpsOde) {
        this.extendGpsOde = extendGpsOde;
    }

    public int getExtendGpsSpeed() {
        return extendGpsSpeed;
    }

    public void setExtendGpsSpeed(int extendGpsSpeed) {
        this.extendGpsSpeed = extendGpsSpeed;
    }

    public int getExtendGpsDirection() {
        return extendGpsDirection;
    }

    public void setExtendGpsDirection(int extendGpsDirection) {
        this.extendGpsDirection = extendGpsDirection;
    }

    public int getExtendDeviceLocationCount() {
        return extendDeviceLocationCount;
    }

    public void setExtendDeviceLocationCount(int extendDeviceLocationCount) {
        this.extendDeviceLocationCount = extendDeviceLocationCount;
    }

    public int getExtendSignalIntensity() {
        return extendSignalIntensity;
    }

    public void setExtendSignalIntensity(int extendSignalIntensity) {
        this.extendSignalIntensity = extendSignalIntensity;
    }

    public ExtendLeasingModelTag getExtendLeasing() {
        return extendLeasing;
    }

    public void setExtendLeasing(ExtendLeasingModelTag extendLeasing) {
        this.extendLeasing = extendLeasing;
    }

    public CommonOpenTag getUsbInternetState() {
        return usbInternetState;
    }

    public void setUsbInternetState(CommonOpenTag usbInternetState) {
        this.usbInternetState = usbInternetState;
    }

    public CommonLockTag getBluetoothState() {
        return bluetoothState;
    }

    public void setBluetoothState(CommonLockTag bluetoothState) {
        this.bluetoothState = bluetoothState;
    }

    public CommonLockTag getDynamicState() {
        return dynamicState;
    }

    public void setDynamicState(CommonLockTag dynamicState) {
        this.dynamicState = dynamicState;
    }

    public CommonEnableTag getPhysicalKeyState() {
        return physicalKeyState;
    }

    public void setPhysicalKeyState(CommonEnableTag physicalKeyState) {
        this.physicalKeyState = physicalKeyState;
    }

    public CommonSwitchTag getLeftFrontDoor() {
        return leftFrontDoor;
    }

    public void setLeftFrontDoor(CommonSwitchTag leftFrontDoor) {
        this.leftFrontDoor = leftFrontDoor;
    }

    public CommonSwitchTag getRightBackDoor() {
        return rightBackDoor;
    }

    public void setRightBackDoor(CommonSwitchTag rightBackDoor) {
        this.rightBackDoor = rightBackDoor;
    }

    public CommonSwitchTag getRightFrontDoor() {
        return rightFrontDoor;
    }

    public void setRightFrontDoor(CommonSwitchTag rightFrontDoor) {
        this.rightFrontDoor = rightFrontDoor;
    }

    public CommonSwitchTag getLeftBackDoor() {
        return leftBackDoor;
    }

    public void setLeftBackDoor(CommonSwitchTag leftBackDoor) {
        this.leftBackDoor = leftBackDoor;
    }

    public CommonSwitchTag getRearDoor() {
        return rearDoor;
    }

    public void setRearDoor(CommonSwitchTag rearDoor) {
        this.rearDoor = rearDoor;
    }

    public CommonSwitchTag getDoorState5() {
        return DoorState5;
    }

    public void setDoorState5(CommonSwitchTag doorState5) {
        DoorState5 = doorState5;
    }

    public CommonSwitchTag getDoorState6() {
        return DoorState6;
    }

    public void setDoorState6(CommonSwitchTag doorState6) {
        DoorState6 = doorState6;
    }

    public CommonSwitchTag getDoorState7() {
        return DoorState7;
    }

    public void setDoorState7(CommonSwitchTag doorState7) {
        DoorState7 = doorState7;
    }

    public CommonSwitchTag getLeftFrontWindow() {
        return leftFrontWindow;
    }

    public void setLeftFrontWindow(CommonSwitchTag leftFrontWindow) {
        this.leftFrontWindow = leftFrontWindow;
    }

    public CommonSwitchTag getRightBackWindow() {
        return rightBackWindow;
    }

    public void setRightBackWindow(CommonSwitchTag rightBackWindow) {
        this.rightBackWindow = rightBackWindow;
    }

    public CommonSwitchTag getRightFrontWindow() {
        return rightFrontWindow;
    }

    public void setRightFrontWindow(CommonSwitchTag rightFrontWindow) {
        this.rightFrontWindow = rightFrontWindow;
    }

    public CommonSwitchTag getLeftBackWindow() {
        return leftBackWindow;
    }

    public void setLeftBackWindow(CommonSwitchTag leftBackWindow) {
        this.leftBackWindow = leftBackWindow;
    }

    public CommonSwitchTag getWindow4() {
        return window4;
    }

    public void setWindow4(CommonSwitchTag window4) {
        this.window4 = window4;
    }

    public CommonSwitchTag getWindow5() {
        return window5;
    }

    public void setWindow5(CommonSwitchTag window5) {
        this.window5 = window5;
    }

    public CommonSwitchTag getWindow6() {
        return window6;
    }

    public void setWindow6(CommonSwitchTag window6) {
        this.window6 = window6;
    }

    public CommonSwitchTag getWindow7() {
        return window7;
    }

    public void setWindow7(CommonSwitchTag window7) {
        this.window7 = window7;
    }

    public CommonSwitchTag getLowBeam() {
        return lowBeam;
    }

    public void setLowBeam(CommonSwitchTag lowBeam) {
        this.lowBeam = lowBeam;
    }

    public CommonSwitchTag getHighBeam() {
        return highBeam;
    }

    public void setHighBeam(CommonSwitchTag highBeam) {
        this.highBeam = highBeam;
    }

    public CommonSwitchTag getFrontFogLamp() {
        return frontFogLamp;
    }

    public void setFrontFogLamp(CommonSwitchTag frontFogLamp) {
        this.frontFogLamp = frontFogLamp;
    }

    public CommonSwitchTag getRearFogLamp() {
        return rearFogLamp;
    }

    public void setRearFogLamp(CommonSwitchTag rearFogLamp) {
        this.rearFogLamp = rearFogLamp;
    }

    public CommonSwitchTag getReadingLamp() {
        return readingLamp;
    }

    public void setReadingLamp(CommonSwitchTag readingLamp) {
        this.readingLamp = readingLamp;
    }

    public CommonSwitchTag getLamp5() {
        return lamp5;
    }

    public void setLamp5(CommonSwitchTag lamp5) {
        this.lamp5 = lamp5;
    }

    public CommonSwitchTag getLamp6() {
        return lamp6;
    }

    public void setLamp6(CommonSwitchTag lamp6) {
        this.lamp6 = lamp6;
    }

    public CommonSwitchTag getLamp7() {
        return lamp7;
    }

    public void setLamp7(CommonSwitchTag lamp7) {
        this.lamp7 = lamp7;
    }


    @Override
    public String toString() {
        return "VehicleState [长度=" + extendLength
                + "\r\n 电源档位=" + extendPowerGear
                + "\r\n 租赁模式=" + extendLeasingModel
                + "\r\n 车门状态=" + extendDoorState
                + "\r\n 车窗状态=" + extendWindowState
                + "\r\n 中控锁=" + extendControlLockState
                + "\r\n 车灯=" + extendLightState
                + "\r\n 手刹=" + extendHandBrakeState
                + "\r\n 蓄电池电压=" + extendBatteryVoltage
                + "\r\n 充电枪=" + extendChargingGunState
                + "\r\n 定位状态=" + extendLocationState
                + "\r\n GPS里程=" + extendGpsOde + "\r\n GPS速度="
                + extendGpsSpeed + "\r\n Gps方向角=" + extendGpsDirection
                + "\r\n 设备定位星数=" + extendDeviceLocationCount
                + "\r\n 信号强度=" + extendSignalIntensity
                + "\r\n 租赁=" + extendLeasing + "\r\n USB上网="
                + usbInternetState + "\r\n 蓝牙=" + bluetoothState
                + "\r\n 动力=" + dynamicState + "\r\n 钥匙="
                + physicalKeyState + "\r\n 左前门=" + leftFrontDoor
                + "\r\n 右后门=" + rightBackDoor + "\r\n 右前门="
                + rightFrontDoor + "\r\n 左后门=" + leftBackDoor
                + "\r\n 后备箱=" + rearDoor + "\r\n 车门5=" + DoorState5
                + "\r\n 车门6=" + DoorState6 + "\r\n 车门7=" + DoorState7
                + "\r\n 左前窗=" + leftFrontWindow + "\r\n 右后窗="
                + rightBackWindow + "\r\n 右前窗=" + rightFrontWindow
                + "\r\n 左后窗=" + leftBackWindow + "\r\n window4=" + window4
                + "\r\n window5=" + window5 + "\r\n window6=" + window6
                + "\r\n window7=" + window7 + "\r\n  近光灯=" + lowBeam
                + "\r\n  远光灯=" + highBeam + "\r\n  前雾灯=" + frontFogLamp
                + "\r\n  后雾灯=" + rearFogLamp + "\r\n  阅读灯="
                + readingLamp + "\r\n  lamp5=" + lamp5 + "\r\n  lamp6=" + lamp6
                + "\r\n  lamp7=" + lamp7 + "]";
    }

}